package com.Yourweibo.adapter;

import java.util.List;

import weibo4android.Status;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.Yourweibo.R;
import com.Yourweibo.util.ImageLoadAsync;

public class PubllicTimeAdapter extends ArrayAdapter<Status> {
	private Context context;
	private ViewHolder viewHolder;
	private List<Status> TimelineList;
 
	public PubllicTimeAdapter(Context context, int textViewResourceId,
			List<Status> list) {
		super(context, textViewResourceId, list);
		// TODO Auto-generated constructor stub
		this.context=context;
		TimelineList=list;
	}

 

	 
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return TimelineList.size();
	}

	 

	@Override
	public Status getItem(int position) {
		// TODO Auto-generated method stub
		return TimelineList.get(position);
	}




	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		
	 
		if(convertView==null){
			convertView=View.inflate(context, R.layout.public_timeline_layout, null);
			viewHolder=new ViewHolder();
			convertView.setTag(viewHolder);
		} else{
			viewHolder=(ViewHolder)convertView.getTag();
			
		}
 
	 	viewHolder.userName=(TextView)convertView.findViewById(R.id.login_public_timeline_username);
	 	viewHolder.userText=(TextView)convertView.findViewById(R.id.login_public_timeline_text);
	 	viewHolder.time=(TextView)convertView.findViewById(R.id.login_public_timeline_time);
	//	viewHolder.userName.setText(user.getName());
	 	viewHolder.userPhoto=(ImageView)convertView.findViewById(R.id.login_public_timeline_userphoto);
	 /*	Drawable cacheImage=imageLoader.LoadDrawalbe(TimelineList.get(position).getUser().getProfileImageURL().toString(),new ImageLoadAsync.ImageCallback() {
			
			@Override
			public void imageLoaded(Drawable imageDrawable) {
				// TODO Auto-generated method stub
				
				viewHolder.userPhoto.setImageDrawable(imageDrawable);
			}
		});
	 	
	 	if (cacheImage != null) {
	 		viewHolder.userPhoto.setImageDrawable(cacheImage);
		}*/
	 /*	String imgurl=TimelineList.get(position).getUser().getProfileImageURL().toString();
	 	Drawable cacheImage;
		try {
			cacheImage = Drawable.createFromStream(new URL(imgurl).openStream(),"image.png");
			viewHolder.userPhoto.setImageDrawable(cacheImage);
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
	
	 	
	 	
	 	viewHolder.userName.setText(TimelineList.get(position).getUser().getName());
	 	viewHolder.userText.setText(TimelineList.get(position).getText());
	 	viewHolder.time.setText(TimelineList.get(position).getUser().getCreatedAt().toGMTString());
	 	TimelineList.get(position).getUser().getProfileImageURL();
		return convertView;
	}
	 
 	ImageLoadAsync imageLoader=new ImageLoadAsync();
	static class ViewHolder{
		ImageView userPhoto;
		TextView userName;
		TextView userText;
		TextView time;
		
		
	}
}
